package com.xzgj.api.web;

import com.alibaba.cola.dto.MultiResponse;
import com.xzgj.api.api.DemoApi;
import com.xzgj.api.dto.data.DemoAddDto;
import com.xzgj.api.entity.DemoEntity;
import com.xzgj.api.service.DemoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * Demo类
 * @author hxh
 * @version 1.0.0
 * @date 2024/3/6
 */
@RestController
@RequestMapping("/demo")
public class DemoController {

    @Autowired
    private DemoService demoService;
    @Autowired
    private DemoApi demoApi;

    @GetMapping("/hello-world")
    public String helloWord() {
        return "Hello World";
    }

    @GetMapping("/list")
    public MultiResponse<DemoEntity> listAll() {
        List<DemoEntity> list = demoService.list();
        return MultiResponse.of(list);
    }

    /**
     *
     * @param demoAddDto
     */
    @PostMapping("/add")
    public void add(@RequestBody @Validated DemoAddDto demoAddDto) {
        demoApi.add(demoAddDto);
    }
}
